package es.efor.ics.gev.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Version;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The persistent class for the <b>CARGOS</b> database table.
 * 
 * @author dlisbona
 * 
 */
@Entity
@Table(name = "CARGOS")
public class Cargo extends BaseObject implements Serializable {

	// static data
	private static final long serialVersionUID = -2225363845593362210L;

	// private instance data
	private Long id;
	private String nombreCargo; // required
	boolean creditos;
	private Integer version;
	
	/**
	 * Construct an uninitialized <code>Cargo</code> (for runtime proxy
	 * generation in Hibernate).
	 */
	protected Cargo() {		
	}
	
	/**
	 * Construct an initialized <code>Cargo</code>.
	 * 
	 * @param nombreCargo
	 */
	public Cargo(String nombreCargo) {
		this.nombreCargo = nombreCargo;
	}
	
	// ********************** Accessor Methods ********************** //
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "CARGO_ID")
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	
	@Column(name = "NOMBRE_CARGO", nullable = false)
	public String getNombreCargo() {
		return nombreCargo;
	}

	public void setNombreCargo(String nombreCargo) {
		this.nombreCargo = nombreCargo;
	}
	
	@Column(name = "CREDITOS")	
	public boolean isCreditos() {
		return creditos;
	}

	public void setCreditos(boolean creditos) {
		this.creditos = creditos;
	}

	@Version
	@Column(name = "OBJ_VERSION")
	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	// ********************** Common Methods ********************** //
	
	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Cargo == false) {
			return false;
		}
		if (this == obj) {
			return true;
		}
		Cargo rhs = (Cargo) obj;
		return new EqualsBuilder()
				.append(this.getNombreCargo(), rhs.getNombreCargo()).isEquals();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder(17, 37).append(this.getNombreCargo())
		.toHashCode();
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE).append(
				"nombreCargo", this.getNombreCargo()).toString();
	}

}
